package com.vhuomai.system.service.impl;

import com.quanyue.auto.util.GlobalContext;
import com.vhuomai.system.entity.BaseSysMerchant;
import com.vhuomai.system.mapper.MerchantMapper;
import com.vhuomai.system.service.MerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author harris
 */
@Service
public class MerchantServiceImpl implements MerchantService {

    @Autowired
    private MerchantMapper merchantMapper;

    @Override
    public BaseSysMerchant find() {
        return merchantMapper.findByMerchantNo(GlobalContext.merchantNo());
    }

    @Override
    public BaseSysMerchant findByDomain(String domain) {
        return merchantMapper.findByDomain(domain);
    }

    @Override
    public BaseSysMerchant add(BaseSysMerchant merchant) {
        merchant.setForbidden(false);
        merchant.setCreateTime(LocalDateTime.now());
        merchant.setUpdateTime(merchant.getCreateTime());
        merchantMapper.insertOne(merchant);
        return merchant;
    }

    @Override
    public void update(BaseSysMerchant merchant) {
        merchant.setUpdateTime(LocalDateTime.now());
        merchantMapper.updateSelective(merchant);
    }
}
